﻿using NUnit.Framework;

namespace WordStudy20250123.Other
{
    [TestFixture]
    internal class Other003
    {
        const double Pi = 3.14159265358979323846;

        [Test]
        public void Test01()
        {
            int count = 5;
            double radius = 5.0;
            double area = Area1(count, radius);
            Console.WriteLine($"方法外  count:{count} radius :{radius} area:{area}");
        }

        public double Area1(int count, double radius)
        {
            count = 10;
            radius = 10.0;
            double area = count * Pi * radius * radius;
            Console.WriteLine($"方法内  count:{count} radius :{radius} area:{area}");
            return area;
        }

        [Test]
        public void Test02()
        {
            int count = 5;
            double radius = 5.0;
            double area = Area2(ref count, ref radius);
            Console.WriteLine($"方法外  count:{count} radius :{radius} area:{area}");
        }

        public double Area2(ref int count, ref double radius)
        {
            count = 10;
            radius = 10.0;
            double area = count * Pi * radius * radius;
            Console.WriteLine($"方法内  count:{count} radius :{radius} area:{area}");
            return area;
        }

        [Test]
        public void Test03()
        {
            int count;
            double radius;
            double area = Area3(out count, out radius);
            Console.WriteLine($"方法外  count:{count} radius :{radius} area:{area}");
        }

        public double Area3(out int count, out double radius)
        {
            count = 10;
            radius = 10.0;
            double area = count * Pi * radius * radius;
            Console.WriteLine($"方法内  count:{count} radius :{radius} area:{area}");
            return area;
        }

        [Test]
        public void Test04()
        {
            Console.WriteLine(Sum(2, 4, 6, 8, 10));
            Console.WriteLine("=====================================");
            Console.WriteLine(Sum(new int[] { 2, 4, 6, 8, 10 }));
        }

        public int Sum(params int[] numbers)
        {
            int sum = 0;
            foreach (int number in numbers)
            {
                sum += number;
            }
            return sum;
        }

        [Test]
        public void TestDoubleFormatting()
        {
            double testValue = 1234.5678;

            // 测试不同的格式化方式
            string format1 = testValue.ToString("F2"); // 保留两位小数
            string format2 = testValue.ToString("N3"); // 带千分位分隔符，保留三位小数
            string format3 = testValue.ToString("E"); // 科学计数法

            // 输出结果
            Console.WriteLine("F2 格式: " + format1);
            Console.WriteLine("N3 格式: " + format2);
            Console.WriteLine("E 格式: " + format3);

            // 断言验证
            Assert.That(format1, Is.EqualTo("1234.57"));
            Assert.That(format2, Is.EqualTo("1,234.568"));
            Assert.That(format3, Is.EqualTo("1.234568E+003"));
        }

        [Test]
        public void Test05()
        {
            Dictionary<string, string> dirt = new Dictionary<string, string>
            {
                { "key1", "value1" },
                { "key2", "value2" }
            };
            dirt["key3"] = "value3";
            foreach (var item in dirt)
            {
                Console.WriteLine(item);
            }
        }
    }
}
